package memorphic.slide
{
	
	[Exclude]
	
	// TODO, add a static cache so only need to do this once if the same view is used twice
	public class CascadeInfo
	{
		
		private var typeDescription:XML;
		
		private var cachedPropNames:Array;
		
		
		public function get numProps():uint
		{
			return getCascadingPropertyNames().length;
		}
		
		public function CascadeInfo(typeDescription:XML)
		{
			this.typeDescription = typeDescription;
		}
	
	/*
		public function getCascadingPropertyNames():Array
		{
			if(!cachedPropNames){
				cachedPropNames = new Array();
				var propDescr:XMLList = typeDescription.accessor;
				var meta:XMLList = propDescr.metadata.(@name == "Bindable").arg.(@key == "cascadeValue" && @value == "true");
				if(meta.length() > 0){
					for each(var m:XML in meta){
						var node:XML = m.parent() as XML;
						
						cachedPropNames.push(new CascadeInfoItem(node.@name));
					}
				}
			}
			
			return cachedPropNames;
		}
	*/
		public function getCascadingPropertyNames():Array
		{
			if(!cachedPropNames){
				cachedPropNames = new Array();
				var propDescr:XMLList = typeDescription.accessor;
				var meta:XMLList = propDescr.metadata.(@name == "Cascade");
				if(meta.length() > 0){
					var bindableTags:XMLList = propDescr.metadata.(@name == "Bindable");
					if(bindableTags.length() < 1){
						throw new Error("Properties with the Cascade tag, must also be Bindable");
					}
					for each(var m:XML in meta){
						var node:XML = m.parent() as XML;
						//cachedPropNames[node.@name] = true;
						cachedPropNames.push(new CascadeInfoItem(node.@name));
					}
				}
			}
			
			return cachedPropNames;
		}
	
	}
}